﻿using System;
using MySql.Data.MySqlClient;

namespace App_Code
{
    /// <summary>
    /// Summary description for BugReportController
    /// </summary>
    public class BugReportController
    {
        static readonly string _connStr = String.Format("server={0};uid={1};pwd={2};database={3};Allow User Variables=True;",
                                                        "anotherurl.com", "root", "rootpw!", "bugreport");
        /*         
            use BugReport;
            select * from reports;         
          */
        public void SubmitReport(string ip, string report)
        {
            string time = String.Format("{0:yyyy-M-dd HH:mm:ss}", DateTime.UtcNow);

            try
            {
                string sql = "INSERT INTO reports(ip, report, time) VALUES(\"" + ip + "\", \"" + report + "\", \"" + time + "\");";

                using (var conn = new MySqlConnection(_connStr))
                {
                    conn.Open();

                    using (var cmd = new MySqlCommand(sql, conn))
                    {
                        cmd.ExecuteNonQuery();
                    }

                    conn.Close();
                }
            }
            catch (Exception)
            {
            }
        }
    }
}